<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-button
        v-permission="['admin.cacheManage.clear']"
        class="filter-item"
        type="primary"
        icon="el-icon-brush"
        @click="clearAllCacheKey"
      >清除缓存({{ cacheTotalSize }})</el-button>
    </div>
  </div>
</template>

<script>
import { clearAllCacheKey, listAllCacheKey } from '@/api/cacheManage'
export default {
  name: 'CacheManage',
  components: { },
  filters: {
  },
  data() {
    return {
      cacheTotalSize: 0
    }
  },
  created() {
    this.listAllCacheKey()
  },
  methods: {
    listAllCacheKey() {
      listAllCacheKey()
        .then(response => {
          this.cacheTotalSize = response.data.data ? response.data.data.length : 0
        })
        .catch(() => {
          this.cacheTotalSize = 0
        })
    },
    clearAllCacheKey() {
      this.$confirm('此操作将清空系统设置的缓存, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        clearAllCacheKey()
          .then(response => {
            var result = response.data.data && response.data.data.total ? response.data.data.total : 0
            this.$notify.success({
              title: '成功',
              message: '清除成功,已清除' + result + '处'
            })
            this.listAllCacheKey()
            this.cacheTotalSize = result
          })
          .catch(response => {
            this.$notify.error({
              title: '失败',
              message: '失败'
            })
          })
      }).catch(() => {
        return false
      })
    }
  }
}
</script>

<style>
</style>
